<?php
/**
 * Adept Framework
 * 
 * @copyright   Copyright &copy; 2006-2007
 * @license     http://www.gnu.org/copyleft/lesser.html
 * @package     
 * @version     $id:$ 
 */

require_once('Adept/Filter/IFilter.php');

class Adept_Application 
{

    protected $context;
    protected $filterChain;

    public function __construct() 
    {
        $this->filterChain = new Adept_Filter_Chain();
        $this->context = Adept_Context::getInstance();
    }

    /**
     * @param Adept_Filter_IFilter $filter
     */
    protected function registerFilter(Adept_Filter_IFilter $filter)     
    {
        $this->filterChain->append($filter);
    }

    public function run() 
    {
        try {
            // run services
            $this->filterChain->next();
        } catch (Adept_Exception_Error404 $e) {
            Adept_Context::getInstance()->getResponse()->redirect("/404/");
        } catch (Exception $e) {
            echo $e->__toString();
        }
    }

    public function getContext() 
    {
        return $this->context;
    }

}

